package cn.itcast.server.service;

import cn.itcast.config.Config;
import redis.clients.jedis.Jedis;

import java.util.Properties;

public class RedisService {

    private static Jedis jedis = null;

    static {
        try {
            Properties properties = Config.getProperties();

            String redisHost = "localhost";
            String property0 = properties.getProperty("redis.host");
            if (null != property0) {
                redisHost = property0;
            }

            int redisPort = 6379;
            String property1 = properties.getProperty("redis.port");
            if (null != property1) {
                redisPort = Integer.parseInt(property1);
            }

            jedis = new Jedis(redisHost, redisPort);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }


    public static Jedis getJedis() {
        return jedis;
    }


    public static void setValue(String key, String value) {
        jedis.set(key, value);
    }

    public static String getValue(String key) {
        return jedis.get(key);
    }

    public static void main(String[] args) {
        System.out.println(getValue("name"));
    }

}
